public class Heater {
    private State currentState = State.OFF;
    private boolean isEmptyWater = true; // 默认没水


    private State state;

    public Heater() {
        this.state = State.OFF; // 默认状态为关闭
    }

    // 设置烧水器状态的方法
    public void setState(State newState) {
        this.state = newState;
    }

    // 设置是否有水
    public void setEmptyWater(boolean isEmpty) {
        this.isEmptyWater = isEmpty;
    }

    // 获取当前状态
    public State getCurrentState() {
        return currentState;
    }



    // 处理事件
    public void fire(Event event) {
        switch (event) {
            case turnOn:
                if (!isEmptyWater && currentState != State.ON) {
                    currentState = State.ON;
                } else if (isEmptyWater) {
                    System.out.println("没水，保持关闭状态");
                } else {
                    System.out.println("已经在烧水状态，无需重复打开");
                }
                break;
            case turnOff:
                if (currentState == State.ON) {
                    currentState = State.OFF;
                } else {
                    System.out.println("已经在关闭状态，无需重复关闭");
                }
                break;
            case burningOut:
                throw new IllegalStateException("当前状态不接受指定事件：烧水器故障");
            default:
                throw new IllegalArgumentException("未知的事件类型：" + event);
        }
    }

    public void checkException(Event event, String expectedMessage) {
        try {
            fire(event);
        } catch (Exception e) {
            return; // 如果抛出了预期的异常，则测试通过
        }
    }
}